package com.outsider.service;

import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.NutDao;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import com.alibaba.druid.pool.DruidDataSource;
import com.outsider.entity.Student;

public class StudentService {
	private static Dao dao;
	static{
		DruidDataSource dds = new DruidDataSource();
		dds.setDriverClassName("com.mysql.jdbc.Driver");
		dds.setUrl("jdbc:mysql://192.168.1.100:3306/webservice");
		dds.setUsername("root");
		dds.setPassword("123456");
	    dao=new NutDao(dds);
	}
	public Student[] getAllStudent(){
		return (dao.query(Student.class, null).toArray(new Student[0]));	
	}
	public Student[] getStudent(String stuID){
		SqlExpressionGroup e1 = null;
		e1=Cnd.exps("stuID", "=", stuID);
		return (dao.query(Student.class,Cnd.where(e1)).toArray(new Student[0]));
	}
    public String delstudent(String stuID){
    	Student student=getStudent(stuID)[0];
        if (student==null)
        	return "该学号不存在";
        else 
        	{  dao.delete(student);
        	   return "已删除";
        	}
    }
    public String addStudent(Student student){
    	dao.insert(student);
    	return "新增成功";
    }
    public String updateStudent(Student student){
    	dao.update(student);
    	return "新增成功";
    }

}
